package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCDemo6 {
    public static void main(String[] args) {
        try (Connection conn = DBUtil.getConnection()){
            Statement statement = conn.createStatement();
            /*
            SELECT t.name,t.gender,c.name,c.floor FROM teacher t,class c WHERE t.name = '王克晶';
             */
            String sql = "SELECT t.name,t.gender,c.name,c.floor FROM teacher t,class c WHERE c.teacher_id = t.id AND t.name = '王克晶';";
            ResultSet rs = statement.executeQuery(sql);
            while(rs.next()){
                String tName = rs.getString("t.name");
                String tGender = rs.getString("t.gender");
                String cName = rs.getString("c.name");
                String cFloor = rs.getString("c.floor");
                System.out.println(tName+"-"+tGender+"-"+cName+"-"+cFloor);
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
